<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <title>活动评论列表</title>
    <link rel="stylesheet" th:href="@{/src/css/layui.css}">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form">
            <div style="float: left; margin-left: 15px; margin-top: 20px;">
                <div class="demoTable">
                    <div class="layui-inline">
                        <label class="layui-form-label">发布者名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="nickName" placeholder="请输入"
                                   autocomplete="off" class="layui-input"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <!--审批状态选择搜索框-->
                        <label class="layui-form-label">活动类型：</label>
                        <div class="layui-input-inline">
                            <select name="dynamicType" lay-search="">
                                <option value="">请选择</option>
                                <option value="0">全部</option>
                                <option value="1">娱乐</option>
                                <option value="2">科普</option>
                                <option value="3">促销</option>
                                <option value="4">其它</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <!--搜索按钮-->
            <div class="layui-inline"
                 style="float: left; margin-left: 30px; margin-top: 20px;">
                <button class="layui-btn" lay-submit=""
                        lay-filter="data-search-btn">搜索
                </button>
            </div>

            <!--清空搜索框按钮-->
            <div class="layui-inline"
                 style="float: left; margin-left: 30px; margin-top: 20px;">
                <button type="reset" class="layui-btn">清空</button>
            </div>
        </form>
    </div>
</div>
<div style="float: left; margin-left: 10px;">
    <table id="dynamic_commentList" class="dynamic_commentList" lay-filter="dynamic_commentList"></table>
</div>
<script th:src="@{/src/layui.js}"></script>

<script>
    layui.use(['jquery', 'layer', 'laypage', 'laytpl', 'table', 'form'], function () {
        var $ = layui.jquery,
            layer = layui.layer,
            laypage = layui.laypage,
            laytpl = layui.laytpl,
            form = layui.form,
            table = layui.table;
        table.render({
            id: 'dynamic_commentList',
            elem: '#dynamic_commentList',
            url: '/dynamic_comment/list',
            title: '投诉列表',
            cellMinWidth: 80,
            page: true,
            limit: 5,
            limits: [5, 10, 20],
            cols: [
                [
                    {type: 'checkbox',width:50},
                    {title: '编号', field: 'id',width:80},
                    {title: '发布者名称', field: 'nickName',width:150},
                    {title: '动态类型', field: 'dynamicType', templet: '#typeEdit',width:150},
                    {title: '动态内容', field: 'dynamicContent',width:150},
                    {title: '获赞数量', field: 'favor',width:110},
                    {title: '发布时间', field: 'issueTime',width:150},
                    {title: '评论内容', field: 'comment',width:160},
                    {title: '评论时间', field: 'commentTime',width:150},
                    {title: '操作', templet: '#barEdit',width:100}
                ]
            ],
            parseData: function (result) {
                return {
                    code: result.code == 200 ? 0 : result.code,
                    msg: result.message,
                    count: result.data.total,
                    data: result.data.list
                }
            }
        })
        table.on('tool(dynamic_commentList)', function (row) {
            var data = row.data;//获取当前行的数据
            var event = row.event;// 获得 lay-event 对应的值

            if (event === 'del') {
                layer.confirm('确认删除', function (index) {
                    $.ajax({
                        url: '/dynamic_comment/delComment/' + data.id,
                        type: 'delete',
                        dataType: 'json',
                        success: function (result) {
                            if (result.code == 200) {
                                layer.msg("删除成功", {icon: 1});
                                location.reload();
                            } else {
                                layer.msg("删除失败", {icon: 5});
                            }
                        }
                    })
                    layer.close(index);
                })
            }
        })
        form.on('submit(data-search-btn)', function (data) {
            var nickName = data.field.nickName;
            var dynamicType = data.field.dynamicType;


            //执行重载
            table.reload('dynamic_commentList', {
                page: {
                    curr: 1
                },
                where: {
                    nickName: nickName,
                    dynamicType:dynamicType
                },
                method: 'get',
                url: '/dynamic_comment/select',
            });
            return false;
        });
    })
</script>

<script type="text/html" id="barEdit">
    <a class="layui-btn layui-btn-xs layui-btn-disabled" lay-event="del" shiro:lacksPermission="sys:dc:delete">删除</a>
    <a class="layui-btn layui-btn-xs" lay-event="del" shiro:hasPermission="sys:dc:delete">删除</a>
</script>


<script type="text/html" id="typeEdit">
    {{# if (d.dynamicType==0) { }}
    <span>全部</span>
    {{# }else if(d.dynamicType==1){ }}
    <span>娱乐</span>
    {{# }else if(d.dynamicType==2){ }}
    <span>科普</span>
    {{# }else if(d.dynamicType==3){ }}
    <span>促销</span>
    {{# }else{ }}
    <span>其它</span>
    {{# } }}
</script>
</body>
</html>